#include "processpool.hpp"
int main()
{
    ProcessPool pp;

    pp.Initprocesspool([](int fd)
                       {
        while (true)
        {
            int code = 0;
            ssize_t n = read(fd, &code, sizeof(code));
            if (n == sizeof(code))
            {
                std::cout << "子进程被唤醒：" << getpid() << std::endl;
                if (code >= 0 && code < tasks.size())
                {
                    tasks[code]();
                }
                else
                {
                    std::cerr << "父进程给我的任务码是不对的: " << code << std::endl;
                }
            }
            else if (n == 0)
            {
                std::cout << "子进程应该退出了: " << getpid() << std::endl;
                break;
            }
            else
            {
                std::cerr << "read fd: " << fd << ", error" << std::endl;
                break;
            }
            } });

    pp.PollingCtrlSubProcess(10);
    pp.WaitSubProcesses();
    std::cout << "父进程控制子进程完成，父进程结束" << std::endl;

    return 0;

}
